(function($){
		$.tabs = {
			defaults : {
				selector : "ui-tab",
				trigger : "click",
				start : 1,
				delay : 300 // 仅在mouseover事件中有用，即事件响应延时
			}
		};
		
		/**
		 * 触发事件
		 */
		$.tabs.triggerEvent = function($tabs, opts) {
			var $head = $tabs.find("." + opts.selector);
			var $body = $tabs.find("." + opts.selector + "-panels");
			$.tabs._action($head, $body, opts, opts.start - 1);
			$.tabs.triggerEvent[opts.trigger] ? $.tabs.triggerEvent[opts.trigger]($head, $body, opts) : $.tabs.triggerEvent[$.tabs.defaults.trigger]($head, $body, opts);
		};
		
		/**
		 * click 触发
		 */
		$.tabs.triggerEvent.click = function ($head, $body, opts) {
			$head.children().click(function() {
				var index = $(this).index();
				$.tabs._action($head, $body, opts, index);
			});
		};
		
		/**
		 * mouseover 触发<br/>
		 * 需要options 参数delay
		 */
		$.tabs.triggerEvent.mouseover = function ($head, $body, opts) {
			var timeoutid;
			$head.children().mouseover(function() {
				var index = $(this).index();
				clearTimeout(timeoutid);
				timeoutid = setTimeout(function() {
					$.tabs._action($head, $body, opts, index);
				}, opts.delay);
			}).mouseout(function() {
				clearTimeout(timeoutid);
			});
		};
		
		/**
		 * tab 切换
		 */
		$.tabs._action = function($head, $body, opts, index) {
			var $this = $head.children(":eq("+index+")");
			if(!$this.hasClass(opts.selector + '-curr')) {
				$this.addClass(opts.selector + '-curr') && $this.siblings().removeClass(opts.selector + '-curr');
				
				var $panel = $body.children("div:eq(" + index + ")");
				$panel.siblings().removeClass(opts.selector + '-curr') && $panel.addClass(opts.selector + '-curr');
			}
		};
		
		$.fn.tabs = function(options) {
			var opts = $.extend({}, $.tabs.defaults, options);
			return $(this).each(function(index) {
				$.tabs.triggerEvent($(this), opts);
			});
		};
	})(jQuery);

	$(function(){
		$(".ui-layout-center").tabs();
	});